import 'package:built_collection/built_collection.dart';
import 'package:mobile_app.core/core/domain/entities/learning_content/collection_list_item/collection_list_item.dart';

abstract class GetCollectionIds {
  BuiltSet<String> call({
    required BuiltList<CollectionListItem> collectionListItems,
  });
}

class GetCollectionIdsImpl implements GetCollectionIds {
  const GetCollectionIdsImpl();

  @override
  BuiltSet<String> call({
    required BuiltList<CollectionListItem> collectionListItems,
  }) {
    final collectionIds = <String>{};

    for (final collectionListItem in collectionListItems) {
      switch (collectionListItem) {
        case Collection():
          final collection = collectionListItem;
          collectionIds.add(collection.id);

        case CollectionFolder():
          final collectionFolder = collectionListItem;

          for (final collection in collectionFolder.collections) {
            collectionIds.add(collection.id);
          }
      }
    }

    return collectionIds.build();
  }
}
